package com.zhongyu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhongyu.mapper.RoleMapper;
import com.zhongyu.mapper.UserMapper;
import com.zhongyu.pojo.Permission;
import com.zhongyu.pojo.Role;
import com.zhongyu.service.RoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service("roleService")
public class RoleServiceImpl extends ServiceImpl<RoleMapper,Role> implements RoleService {
    @Resource
    private RoleMapper roleMapper;
    @Resource
    private UserMapper userMapper;
    @Override
    public List<Role> searchAll() {
        return roleMapper.selectList(null);
    }

    @Override
    public List<Role> searchAll(Integer id) {
      List<Integer> userRole=userMapper.userRole(id);
       List<Role> list=super.list();
       for(Role r:list){
           if(userRole.contains(r.getId())){
              r.set_checked(true);
           }
       }
        return list;
    }

    @Override
    public void add(Role role) {
        roleMapper.insert(role);

    }

    @Override
    public void del(Integer id) {
    roleMapper.deleteById(id);
    }

    @Override
    public void update(Role role) {

        roleMapper.updateById(role);

    }

    @Override
    public Role selectById(Integer id) {
        return roleMapper.selectById(id);
    }

    @Override
    public void batchDel(Integer[] ids) {
        roleMapper.batchDel(ids);
    }
}
